/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nxlv2.nomad.view.ficheClient;

import com.nxlv2.nomad.businessobjects.Adresse;
import com.nxlv2.nomad.businessobjects.Contact;
import java.awt.Color;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author casey
 */
class TableRenderer extends DefaultTableCellRenderer {

    // Cette méthode permet de ' dessiner ' une cellule
    @Override
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
        super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
                row, column);

        this.setText(value.toString());
        if (isDefault(table, row)) {
            this.setBackground(Color.pink);
            this.setForeground(Color.black);
        } 
        else {
            this.setBackground(Color.WHITE);
            this.setForeground(Color.black);
        }
        if(isSelected){
            this.setBackground(table.getSelectionBackground());
            this.setForeground(table.getSelectionForeground());
        }

        return this;
    }

              //rechercher une cellule vide sur la ligne actuelle
    public boolean isDefault(JTable table, int row) {
            if(table.getValueAt(row, 0) instanceof Contact) {
                 Contact cont  = (Contact) table.getValueAt(row, 0);
                 return cont.isDefaut();
            }
            if(table.getValueAt(row, 0) instanceof Adresse) {
                 Adresse adr  = (Adresse) table.getValueAt(row, 0);
                 return adr.isDefaut();
            }
        return false;
    }

}
